<template src="./index.html"></template>

<script>
import UserOrderInfoService from "../../../../_services/user.order.info.service";
import PayService from "../../../../_services/pay.service";
import WxService from "../../../../_services/wx.service";
export default {
  name: "TianDingPatientMeOrderComponent",
  data() {
    return {
      user: {},
      selected: "-1",
      orderList: [],
      orderItem: {},
      showOrder: false
    };
  },
  mounted() {
    this.user = JSON.parse(this.local$.getItem("tdUser"));
    this.GetUserOrderInfoList();
  },
  methods: {
    /**
     * 获取订单列表
     * @param pageIndex 当前页
     */
    GetUserOrderInfoList(pageIndex) {
      this.indicator$.open("正在加载...");
      this.orderList = [];
      let params = {};
      params.userID = this.user.UserID;

      if (this.selected !== "-1") {
        params.payStatus = parseInt(this.selected);
      }

      params.pageIndex = 1;

      params.pageSize = 10000;
      params.orderby = "CreateTime";
      params.isDesc = true;

      UserOrderInfoService.GetUserOrderInfoList(params).then(response => {
        if (response.Data.Items.length > 0) {
          this.orderList = response.Data.Items;
        }
        this.indicator$.close();
      });
    },
    /**
     * 加载更多
     */
    loadMore() {
      this.GetUserOrderInfoList(1);
    },
    /**
     * 显示订单详情
     * @param item 当前点击订单参数
     */
    showDetail(item) {
      this.indicator$.open("请稍后...");
      let params = {};
      params.OrderID = item.OrderID;
      UserOrderInfoService.GetOrderDetailModelByOrderID(params).then(
        response => {
          console.log(response);
          if (response.Data.length > 0) {
            this.showOrder = true;
            this.orderItem = item;
            this.orderItem.ItemTestList = response.Data;
          }
          this.indicator$.close();
        }
      );
    },
    /**
     * 判断订单是否超时15分钟
     * @param object 当前点击订单参数
     */
    timeoutFormat(object, format = 0) {
      let nowDate = new Date();

      let createDate = new Date(object.CreateTime);
      createDate.setMinutes(createDate.getMinutes() + 15);
      if (format === 0) {
        return nowDate > createDate ? false : true;
      } else {
        return createDate.toLocaleString();
      }
    },
    /**
     * 发起支付
     * @param item 当前点击订单参数
     */
    btnPay(item) {
      this.indicator$.open("请稍后...");
      let params = {};
      params.OrderNumber = item.OrderNumber;
      params.UserID = this.user.UserID;
      params.PayType = 0;
      PayService.RequestPayTestItem(params).then(response => {
        if (response.Data) {
          let wxParams = JSON.parse(response.Data.WXJsApiParam);
          wxParams.type = 0;
          wxParams.total = item.TotalFee;
          WxService.JsSdk(wxParams, this.$router);
        }
        this.indicator$.close();
      });
    }
  }
};
</script>

